{extend name='table'}

{block name="button"}
<!--{if auth("add")}-->
<button data-table-id="BaseTable" data-modal='{:url("add")}?type={$type|default=""}' class='layui-btn layui-btn-sm layui-btn-primary'>添加数据</button>
<!--{/if}-->

{/block}

{block name="content"}
<div class="layui-tab layui-tab-card">
    <ul class="layui-tab-title">
        {foreach $types as $t}{if isset($type) and $type eq $t}
        <li class="layui-this" data-open="{:sysuri()}?type={$t}">{$t}</li>
        {else}
        <li data-open="{:sysuri()}?type={$t}">{$t}</li>
        {/if}{/foreach}
    </ul>
    <div class="layui-tab-content">
        {include file='stock_slice/index_search'}
        <table id="BaseTable" data-url="{:request()->url()}" data-target-search="form.form-search"></table>
    </div>
</div>
{/block}

{block name='script'}
<script>
    $(function () {
        // 初始化表格组件
        $('#BaseTable').layTable({
            even: true, height: 'full',
            sort: { field: 'id', type: 'desc' },
            cols: [[
                // {field: 'type', title: '数据类型', minWidth: 140, align: 'center'},
                { field: 'create_date', title: '日期', width: 120, align: 'center', sort: true },
                {field: 'box_num', title: '桶数', width: '50', align: 'center'},
                // {field: 'bulk_weight', title: '散件重量', width: '100', align: 'center'},
                {field: 'total_weight', title: '总重量', width: '100', align: 'center'},
                     { field: 'other_box_num', title: '次品桶数', width: '100', align: 'center' },
                 { field: 'other_total_weight', title: '次品重量', width: '100', align: 'center' },

        { field: 'status', title: '{:lang("1次真空")}', align: 'center', width: 80, templet: '#StatusSwitchTplOne' },

        { field: 'status', title: '{:lang("2次真空")}', align: 'center', width: 80, templet: '#StatusSwitchTplTwo' },
        
                {field: 'remark', title: '备注', minWidth: '150', align: 'center'},                
                {toolbar: '#toolbar', align: 'center', width: 180, title: '数据操作'},
            ]]
        });



        // 数据状态切换操作
        layui.form.on('switch(StatusSwitchOne)', function (obj) {
            var data = {id: obj.value, status_one: obj.elem.checked > 0 ? 1 : 0};
            $.form.load("{:url('stateOne')}", data, 'post', function (ret) {
                if (ret.code < 1) $.msg.error(ret.info, 3, function () {
                    $('#BaseTable').trigger('reload');
                });
                return false;
            }, false);
        });
         // 数据状态切换操作
        layui.form.on('switch(StatusSwitchTwo)', function (obj) {
            var data = { id: obj.value, status_two: obj.elem.checked > 0 ? 1 : 0 };
            $.form.load("{:url('stateTwo')}", data, 'post', function (ret) {
                if (ret.code < 1) $.msg.error(ret.info, 3, function () {
                    $('#BaseTable').trigger('reload');
                });
                return false;
            }, false);
        });

        
    });
</script>

<!-- 列表排序权重模板 -->
<script type="text/html" id="SortInputTpl">
    <input type="number" min="0" data-blur-number="0" data-action-blur="{:sysuri()}" data-value="id#{{d.id}};action#sort;sort#{value}" data-loading="false" value="{{d.sort}}" class="layui-input text-center">
</script>

<!-- 数据状态切换模板 -->
<script type="text/html" id="StatusSwitchTplOne">
    <!--{if auth("state")}-->
    <input type="checkbox" value="{{d.id}}" lay-skin="switch" lay-text="是|否" lay-filter="StatusSwitchOne" {{-d.status_one>0?'checked':''}}>
    <!--{else}-->
    {{-d.status_one ? '<b class="color-green">是</b>' : '<b class="color-red">否</b>'}}
    <!--{/if}-->
</script>

<!-- 数据状态切换模板 -->
<script type="text/html" id="StatusSwitchTplTwo">
    <!--{if auth("state")}-->
<input type="checkbox" value="{{d.id}}" lay-skin="switch" lay-text="是|否" lay-filter="StatusSwitchTwo"
    {{-d.status_two>0?'checked':''}}>
<!--{else}-->
{{-d.status_two ? '<b class="color-green">是</b>' : '<b class="color-red">否</b>'}}
<!--{/if}-->
</script>

<!-- 数据操作工具条模板 -->
<script type="text/html" id="toolbar">
    <!--{if auth('edit')}-->
    <a class="layui-btn layui-btn-primary layui-btn-sm" data-event-dbclick data-title="编辑数据" data-modal='{:url("edit")}?id={{d.id}}'>编 辑</a>
    <!--{/if}-->


    <!--{if auth('info')}-->
    <a class="layui-btn layui-btn-primary layui-btn-sm" data-event-dbclick data-title="数据"
        data-open='{:url("info")}?id={{d.id}}'>详 情</a>
    <!--{/if}-->
</script>
{/block}